package com.wind.util;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Yangccck
 * @Date 2020/2/26 20:29
 * @Version 1.0
 *
 * Bean复制
 *
 */
public class BeanCopyUtils {


	public static<T> List<T> copyProperties(List source,Class<T> target){
		List<T> list = new ArrayList();
		if (source == null||source.size()==0){
			return list;
		}
		source.forEach(r ->{
			T t = null;
			try {
				t = target.newInstance();
				BeanUtil.copyProperties(r,t, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
			} catch (Exception e) {
				e.printStackTrace();
				//throw new Exception("属性拷贝异常~");
			}
			//BeanUtils.copyProperties(r,t);
			list.add(t);
		});
		return list;
	}
}
